package com.zipking.cloud.springbootmybatis.current;

public class AtomicVariablesDemo {
    public static void main(String[] args) {
        MessageNotificationCounter counter = new MessageNotificationCounter();

        // 多个用户同时发送消息
        Thread sender1 = new Thread(() -> {
            counter.receiveMessage();
        });
        Thread sender2 = new Thread(() -> {
            counter.receiveMessage();
        });

        // 用户阅读消息
        Thread reader = new Thread(() -> {
            counter.messagesRead();
        });

        sender1.start();
        sender2.start();
        reader.start();

        try {
            sender1.join();
            sender2.join();
            reader.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Final message count: " + counter.getMessageCount());
    }
}
